const app = getApp()

Page({
    data: {
    },
    //注册方法
    doRegist:function(e){
      var formObject = e.detail.value;
      var username = formObject.username;
      var password = formObject.password;
      if(username.length == 0 || password.length ==0){
        wx.showToast({
          title: '用户名或密码不能为空',
          icon: 'none',
          duration: 3000
        })
      }else{
        wx.showLoading({
          title: '请等待...'
        })
        var url = app.serverUrl;
        //调用请求接口
        wx.request({
          url: url+'/regist',
          method: 'POST',
          data: {
            username: username,
            password: password
          },
          header: {
            'content-type': 'application/json' 
          },
          success:function (res) {
            wx.hideLoading();
            var status = res.data.status;
            if(status == 200){
              wx.showToast({
                title: '注册成功~',
                icon: 'success',
                duration: 3000
              })
              //app.userInfo = res.data.data;
              //修改后的方式
              app.setGlobalUserInfo(res.data.data)
              //console.log(app.getGlobalUserInfo)
              wx.navigateTo({
                url: '../userLogin/login',
              })
            }else if(status == 500){
              wx.showToast({
                title: res.data.msg,
                icon: 'none',
                duration: 3000
              })

            }
          }   
        })
      }
    },

    //页面跳转->登录页
    goLoginPage: function(){
      wx.navigateTo({
        url: '../userLogin/login',
      })
    }
})